
package Servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import Beans.Member;
import Database.DatabaseInterface;
import ServiceInterface.ServiceProxy;


/**
 * Servlet implementation class SimpleMarketPlaceSignUpServlet
 */
public class UpdateMemberServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
   
	//DatabaseInterface proxy = new DatabaseInterface();
	ServiceProxy proxy = new ServiceProxy();
	
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UpdateMemberServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		response.setContentType("text/html");
		Member member = new Member();
		Integer memberId;
		Double fee = 0.0;
		Integer zip = 0;
		
		try {	
			HttpSession session = request.getSession();			
			//member = (Member)	(session.getAttribute("userLoginInfo"));

			String monthlyFee = request.getParameter("monthlyFee");
			String firstName = request.getParameter("firstName");
			String lastName = request.getParameter("lastName");
			String email = request.getParameter("email");
			String address = request.getParameter("address");
			String city = request.getParameter("city");
			String state = request.getParameter("state");
			String zipCode = request.getParameter("zipCode");
			
			memberId = Integer.parseInt(request.getParameter("memberId"));
			if (monthlyFee != null) {
				fee =Double.valueOf(monthlyFee);
			}
			
			if(zipCode != null) {
				zip =Integer.valueOf(zipCode);
			}
			
			member.setFees(fee);
			member.setFirst(firstName);
			member.setLast(lastName);
			member.setEmail(email);
			member.setAddress(address);
			member.setCity(city);
			member.setState(state);
			member.setZip(zip);
			
			member.setMemNum(memberId);
			
			proxy.setEndpoint("http://localhost:8079/VLMS/services/Service");
			
			Integer result = proxy.updateMember(member);
		    out.println(result + " member updated into the database successfully");

		}
		catch (Exception e) {
			e.printStackTrace();
		}
		
	}
}
